﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Agro.Library {
    public class SNJsonResult : System.Web.Mvc.JsonResult {
        string _errorMessage;
        object _data;

        public SNJsonResult() { }
        public SNJsonResult(object data, string errorMessage) {
            base.Data = CreateJsonData(data, errorMessage);
        }
        public SNJsonResult(object data) {
            base.Data = data;
        }
        public new object Data {
            get { return _data; }
            set {
                _data = value;
                base.Data = CreateJsonData(_data, ErrorMessage);
            }
        }
        public string ErrorMessage {
            get { return _errorMessage; }
            set {
                _errorMessage = value;
                base.Data = CreateJsonData(Data, _errorMessage);
            }
        }
        static object CreateJsonData(object data, string errorMessage) {
            var obj = new { Data = data, ErrorMessage = errorMessage, Success = string.IsNullOrEmpty(errorMessage) };
            return obj;
        }
    }
}
